﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.IO;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
using System.Xml;

namespace TemplateH4.Admin
{
    public partial class QLGiaoDien_Theme : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DirectoryInfo resDir = new DirectoryInfo(Server.MapPath("~/App_Themes"));
                DirectoryInfo[] dirinfo = resDir.GetDirectories();

                foreach (DirectoryInfo temp in dirinfo)
                {
                    lstgiaodien.Items.Add(temp.Name);

                }
                lstgiaodien.SelectedIndex = 0;

                // Hien thi hinh cua theme hien tai
                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath("~/config.xml"));

                XmlNode root = doc.DocumentElement;
                imgthumb.ImageUrl = "~/App_Themes/" + root.SelectSingleNode("theme").ChildNodes[0].Value
                    + "/thumb.jpg";
                Label1.Text = root.SelectSingleNode("theme").ChildNodes[0].Value;
                //Response.Write(imgthumb.ImageUrl);
            }





        }

        protected void btnchangetheme_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("~/config.xml"));
            XmlNode root = doc.DocumentElement;
            XmlNode old = root.SelectSingleNode("theme");
            XmlElement logo = doc.CreateElement("theme");
            String newtheme = lstgiaodien.SelectedItem.ToString();
            logo.InnerText = newtheme;
            root.ReplaceChild(logo, old);


            imgthumb.ImageUrl = "~/App_Themes/" + newtheme + "/thumb.jpg";
            Label1.Text = newtheme;
            

            XmlTextWriter writer = new XmlTextWriter(Server.MapPath("~/config.xml"), null);
            writer.Formatting = Formatting.Indented;
            doc.Save(writer);
            Session.Add("themeSelected", newtheme);



        }
    }
}
